<template>
    <div id="app">
        <header>
            <div class="w">
                <h1 class="fl">
                    <img src="@/assets/images/logo.png" alt="">音乐台
                </h1>
                <ul class="fl">
                    <router-link tag="li" to="/" exact>发现音乐</router-link>
                    <router-link tag="li" to="/mine" exact>我的音乐</router-link>
                    <li>3</li>
                    <li>4</li>
                </ul>
                <div class="find-song fr">
                    <input type="text" v-model.trim="find_song" placeholder="音乐/歌手" @keydown.enter="searchMusic">
                    <div class="search-res" v-if="find_song">
                        <router-link tag="p" to="/search" class="search-to">搜索“{{ find_song }}”相关 <i class="iconfont">&#xe61d;</i>
                        </router-link>
                        <el-divider></el-divider>
                        <ul>
                            <li v-for="(item,index) in songData" :key="index">
                                <a :href="item.link">
                                    <div>
                                        <p>{{ item.title }}</p>
                                        <p>歌手：{{ item.author }}</p>
                                        <p>来源:{{ item.type }}</p>
                                    </div>
                                    <img :src="item.pic" alt="" class="fr" width="30" height="30">
                                </a>
                            </li>
                        </ul>
                    </div>
                </div>

            </div>
        </header>
        <div class="bot-line">

        </div>
        <div class="clearfix" style="background-color: black">
            <div class="ww">
                <div class="fl">
                    <Swipe></Swipe>
                </div>
                <div class="fr down-info">
                    <a href="https://music.163.com/#/download"></a>
                </div>
            </div>
        </div>
        <router-view></router-view>
        <Foot></Foot>
    </div>
</template>

<script>

    import Swipe from "@/components/swipe/swipe"
    import Foot from "@/components/foot/foot"

    export default {
        data() {
            return {
                // 搜索词
                find_song: "",
                // 音乐数组
                songData: [],
            }
        },
        methods: {
            searchMusic() {
                this.axios.get("searchMusic?name=" + this.find_song)
                    .then(res => {
                        let leng = res.data.result.length;
                        if (leng > 10) {
                            this.songData = res.data.result;
                            this.songData = this.songData.slice(5);
                            console.log(this.songData)
                        } else {
                            this.songData = res.data.result
                        }

                    })
            },
        },
        components: {
            Swipe,
            Foot
        },
        watch: {
            // find_song() {
            //     delay(() => {
            //         this.searchMusic();
            //     }, 300);
            // },
        }
    }
</script>

<style lang="less" scoped>
    header {
        width: 100%;
        height: 70px;
        background-color: #242424;

        > div {
            height: 100%;

            h1 {
                color: #fff;
                line-height: 70px;
                font-size: 24px;

                img {
                    display: inline-block;
                    width: 30px;
                    vertical-align: middle;
                    margin-right: 10px;
                }
            }

            > ul {
                margin-left: 20px;

                li {
                    padding: 0 20px;
                    float: left;
                    line-height: 70px;
                    font-size: 14px;
                    color: #ccc;
                    cursor: pointer;

                    &:hover {
                        color: #fff;
                        background-color: black;
                    }
                }
            }
        }
    }

    .bot-line {
        height: 5px;
        width: 100%;
        background-color: #C20C0C;
    }

    .current-active {
        color: #fff;
        background-color: black;
        position: relative;

        &::after {
            content: "";
            width: 0;
            height: 0;
            border-width: 0 6px 6px;
            border-style: solid;
            border-color: transparent transparent #C20C0C; /*透明 透明  灰*/
            position: absolute;
            bottom: -1px;
            left: 50%;
            transform: translateX(-50%);
        }
    }

    .find-song {
        width: 200px;
        height: 35px;
        margin-top: 18px;
        margin-left: 50px;
        position: relative;

        &::before {
            content: "";
            position: absolute;
            top: 50%;
            left: 7px;
            transform: translateY(-50%);
            width: 20px;
            height: 20px;
            background: url("./assets/images/search.png") no-repeat center center;
            background-size: contain;
        }

        input {
            border: none;
            width: 100%;
            height: 100%;
            padding-left: 30px;
            border-radius: 18px;
            outline: none;
            color: #333;
        }

        input::-webkit-input-placeholder {
            /* placeholder颜色  */
            color: #9b9b9b;
            /* placeholder字体大小  */
            font-size: 12px;
        }

        .search-res {
            width: 240px;
            padding: 10px 0;
            background-color: #fff;
            margin-top: 5px;
            border-radius: 5px;
            border: 1px solid #e2e2e2;
            position: relative;
            z-index: 999;
            box-shadow: 0 0 3px #e2e2e2;

            p {
                padding: 0 10px;
            }

            .el-divider--horizontal {
                margin: 0;
            }

            .search-to {
                color: #333;
                cursor: pointer;
                background-color: #fff;
                margin-bottom: 10px;

                &::after {
                    border-color: transparent;
                }

                i {
                    font-size: 12px;
                    float: right;
                }
            }

            > ul {
                li {
                    padding: 10px 10px 10px 0;
                    border-bottom: 1px solid #DCDFE6;

                    a {
                        display: flex;
                        justify-content: space-between;

                        div {
                            flex: 1;
                        }
                    }

                    &:hover {
                        background-color: #e2e2e2;
                    }
                }
            }
        }
    }

    .down-info {
        width: 250px;
        height: 336px;
        background: url("./assets/images/download.png") no-repeat 0 0;
        a{
           display: block;
           width: 100%;
           height: 100%;
       }
    }

</style>
